package com.kangzhan.services;

import com.kangzhan.dao.UserMapper;
import com.kangzhan.entiy.User;
import com.kangzhan.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        return userMapper.login(username, password);
    }

    @Override
    public PageUtil getUserList(String userName, Integer sex, Integer pageSize, Integer pageNum) {

        Integer count = userMapper.count(userName, sex);

        PageUtil pageUtil =new PageUtil();
        pageUtil.setPageSize(pageSize);
        pageUtil.setPageNum(pageNum);
        pageUtil.setCount(count);

        pageUtil.setData(userMapper.getUserList(userName, sex, pageUtil.dbIndex, pageUtil.getPageSize()));

        return pageUtil;

    }

    @Override
    public int save(User user) {
        return userMapper.add(user);
    }
}
